<%@ page contentType="text/html; charset=UTF-8"%>
<%@ taglib prefix="f" uri="http://java.sun.com/jsf/core"%>
<%@ taglib prefix="h" uri="http://java.sun.com/jsf/html"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<html>
<head>
<title>Resource Management</title>
</head>
<link rel="stylesheet" href="../../../resources/css/fw-edit.css"
	type="text/css">
<script src="../../../script/base.js"></script>
<script language="JavaScript">
  function changeType(){
    _type = get2('myForm','type');
    type = _type.options[_type.selectedIndex].value;
    var groups = get2('myForm','group_pks');

    if (type=='P' || type=='I'){
	  if (groups.length == null){
	    groups.checked = false;
	  }else{
	    for (i = 0;i < groups.length; ++i)
		groups[i].checked = false;
	  }
    }

    var d = (type=='P' || type=='I');
  
    if (groups.length == null){
       groups.disabled = d;
    }else{
       for (i = 0;i < groups.length; ++i)
  	     groups[i].disabled = d;
    }
}
</script>
<body>
<f:view>	<f:loadBundle basename="net.orange.conf.lang.fw" var="msg" />

	<h:form id="myForm">
		<h:inputHidden value="#{resource.content.pk}" id="pk" />
		<h:inputHidden value="#{resource.editMode}" id="editMode" />

		<h:panelGrid columns="2" rowClasses="content-title"
			style="width:100%;">
			<h:outputText value="#{msg.resource_title}." />

			<h:panelGroup style="text-align:right">
				<h:commandButton value="#{msg.common_edit}" type="submit" id="cmdEdit"
					action="#{resource.edit}" styleClass="button-normal"
					rendered="#{not resource.editMode}" />

				<h:commandButton value="#{msg.common_save}" type="submit" id="cmdSave"
					action="#{resource.save}" styleClass="button-normal"
					rendered="#{resource.editMode}" />

				<h:outputText value="    " />
				<h:commandButton value="#{msg.common_cancel}" type="submit" id="cmdCancel"
					action="#{resource.back}" styleClass="button-normal" />
			</h:panelGroup>
		</h:panelGrid>

		<hr>

		<h:messages styleClass="content-message" />

		<h:panelGrid columns="2" styleClass="content-table"
			columnClasses="content-detail-title,content-detail">

			<h:outputLabel value="#{msg.common_pk}:" />
			<h:outputText value="#{resource.content.pk}" />

			<h:outputLabel value="#{msg.resource_type}:" />
			<h:selectOneMenu value="#{resource.content.type}" id="type"
				onchange="changeType();" disabled="#{not resource.editMode}">
				<f:selectItems value="#{resource.typelist}" />
			</h:selectOneMenu>

			<h:outputLabel value="#{msg.resource_name}:" />
			<h:inputText value="#{resource.content.name}" id="name"
				disabled="#{not resource.editMode}" style="width:360px" />

			<h:outputLabel value="#{msg.resource_url}:" />
			<h:inputText value="#{resource.content.resource}" id="resource"
				disabled="#{not resource.editMode}" style="width:360px" />

			<h:outputLabel value="#{msg.resource_group}:" />
			<h:selectManyListbox id="group_pks" value="#{resource.group_pks}"
				disabled="#{not resource.editMode}" size="5" style="width:360px">
				<f:selectItems value="#{group.groups}" />
			</h:selectManyListbox>

			<h:outputLabel value="#{msg.common_description}:" />
			<h:inputTextarea value="#{resource.content.description}"
				id="description" disabled="#{not resource.editMode}"
				style="width:360px" rows="3" />
		</h:panelGrid>
	</h:form>
</f:view>
</body>
<script>
<c:if test="${resource.editMode}">
	changeType();
</c:if>
</script>
</html>
